/*
 * GenNum - an ugly way to grab each day's game number from a cache
 *
 * Copyright 2007 James W. Hofmann
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

class GenNum
{

	public static var data : Array<Int>;
	static inline var startdate = Date.fromString("2007-12-04 00:00:00");
	static inline var dayinms = 1000*60*60*24;
	
	static public function todaysgame(date : Date) : Int
	{
		return data[todaysindex(date)];
	}
	
	static public inline function todaysindex(date : Date) : Int
	{
		var starttime = startdate.getTime();
		var curtime = date.getTime();
		var elapsed = curtime - starttime;
		var numtoget = Std.int(elapsed/dayinms);
		return numtoget;
	}
	
	static public function load()
	{
		// only use this to insert into the db....otherwise, it's not
		// necessary to use the sortednumbers file! Use the db instead!
		
		var f = neko.io.File.getContent("sortednumbers");
		var strdata = f.split(" ");
		data = new Array();
		for (n in strdata)
			data.push(Std.parseInt(n));
	}
		
}
